from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-08 14:05:01.387561
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 08, Nov, 2022
Time: 14:05:07
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.9031
Nobs: 834.000 HQIC: -51.2176
Log likelihood: 10878.7 FPE: 4.69406e-23
AIC: -51.4132 Det(Omega_mle): 4.21659e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297868 0.050952 5.846 0.000
L1.Burgenland 0.109293 0.034921 3.130 0.002
L1.Kärnten -0.106459 0.018599 -5.724 0.000
L1.Niederösterreich 0.210353 0.073032 2.880 0.004
L1.Oberösterreich 0.101024 0.069494 1.454 0.146
L1.Salzburg 0.251160 0.037046 6.780 0.000
L1.Steiermark 0.035496 0.048610 0.730 0.465
L1.Tirol 0.106988 0.039375 2.717 0.007
L1.Vorarlberg -0.059053 0.033943 -1.740 0.082
L1.Wien 0.057656 0.062339 0.925 0.355
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.068281 0.105205 0.649 0.516
L1.Burgenland -0.031485 0.072104 -0.437 0.662
L1.Kärnten 0.047380 0.038403 1.234 0.217
L1.Niederösterreich -0.172875 0.150794 -1.146 0.252
L1.Oberösterreich 0.378683 0.143489 2.639 0.008
L1.Salzburg 0.288693 0.076492 3.774 0.000
L1.Steiermark 0.106055 0.100367 1.057 0.291
L1.Tirol 0.315938 0.081299 3.886 0.000
L1.Vorarlberg 0.023491 0.070085 0.335 0.737
L1.Wien -0.017610 0.128717 -0.137 0.891
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195138 0.026314 7.416 0.000
L1.Burgenland 0.092018 0.018035 5.102 0.000
L1.Kärnten -0.008899 0.009605 -0.926 0.354
L1.Niederösterreich 0.266363 0.037717 7.062 0.000
L1.Oberösterreich 0.116544 0.035890 3.247 0.001
L1.Salzburg 0.051397 0.019132 2.686 0.007
L1.Steiermark 0.016796 0.025104 0.669 0.503
L1.Tirol 0.097359 0.020335 4.788 0.000
L1.Vorarlberg 0.057467 0.017530 3.278 0.001
L1.Wien 0.116883 0.032195 3.631 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105228 0.026980 3.900 0.000
L1.Burgenland 0.046623 0.018491 2.521 0.012
L1.Kärnten -0.017073 0.009848 -1.734 0.083
L1.Niederösterreich 0.195642 0.038671 5.059 0.000
L1.Oberösterreich 0.282527 0.036798 7.678 0.000
L1.Salzburg 0.119803 0.019616 6.107 0.000
L1.Steiermark 0.102498 0.025739 3.982 0.000
L1.Tirol 0.121667 0.020849 5.836 0.000
L1.Vorarlberg 0.069914 0.017973 3.890 0.000
L1.Wien -0.027569 0.033009 -0.835 0.404
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127928 0.048982 2.612 0.009
L1.Burgenland -0.049687 0.033571 -1.480 0.139
L1.Kärnten -0.039778 0.017880 -2.225 0.026
L1.Niederösterreich 0.165753 0.070208 2.361 0.018
L1.Oberösterreich 0.139445 0.066807 2.087 0.037
L1.Salzburg 0.284589 0.035614 7.991 0.000
L1.Steiermark 0.033801 0.046730 0.723 0.469
L1.Tirol 0.163416 0.037852 4.317 0.000
L1.Vorarlberg 0.104947 0.032631 3.216 0.001
L1.Wien 0.071314 0.059929 1.190 0.234
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060811 0.038752 1.569 0.117
L1.Burgenland 0.041762 0.026559 1.572 0.116
L1.Kärnten 0.049681 0.014146 3.512 0.000
L1.Niederösterreich 0.227260 0.055544 4.092 0.000
L1.Oberösterreich 0.272474 0.052853 5.155 0.000
L1.Salzburg 0.057949 0.028175 2.057 0.040
L1.Steiermark -0.008362 0.036970 -0.226 0.821
L1.Tirol 0.155751 0.029946 5.201 0.000
L1.Vorarlberg 0.069005 0.025815 2.673 0.008
L1.Wien 0.074378 0.047412 1.569 0.117
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180626 0.046398 3.893 0.000
L1.Burgenland -0.004627 0.031800 -0.146 0.884
L1.Kärnten -0.061041 0.016937 -3.604 0.000
L1.Niederösterreich -0.085628 0.066504 -1.288 0.198
L1.Oberösterreich 0.191583 0.063283 3.027 0.002
L1.Salzburg 0.058806 0.033735 1.743 0.081
L1.Steiermark 0.227263 0.044265 5.134 0.000
L1.Tirol 0.494132 0.035855 13.781 0.000
L1.Vorarlberg 0.049182 0.030909 1.591 0.112
L1.Wien -0.048378 0.056768 -0.852 0.394
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156523 0.052884 2.960 0.003
L1.Burgenland -0.009737 0.036245 -0.269 0.788
L1.Kärnten 0.064911 0.019305 3.362 0.001
L1.Niederösterreich 0.201790 0.075801 2.662 0.008
L1.Oberösterreich -0.066983 0.072129 -0.929 0.353
L1.Salzburg 0.222077 0.038451 5.776 0.000
L1.Steiermark 0.114232 0.050453 2.264 0.024
L1.Tirol 0.082785 0.040867 2.026 0.043
L1.Vorarlberg 0.123693 0.035230 3.511 0.000
L1.Wien 0.112283 0.064703 1.735 0.083
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.353206 0.030961 11.408 0.000
L1.Burgenland 0.008085 0.021220 0.381 0.703
L1.Kärnten -0.024464 0.011302 -2.165 0.030
L1.Niederösterreich 0.227092 0.044378 5.117 0.000
L1.Oberösterreich 0.163238 0.042228 3.866 0.000
L1.Salzburg 0.051952 0.022511 2.308 0.021
L1.Steiermark -0.016189 0.029538 -0.548 0.584
L1.Tirol 0.114195 0.023926 4.773 0.000
L1.Vorarlberg 0.072936 0.020626 3.536 0.000
L1.Wien 0.051009 0.037881 1.347 0.178
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043173 0.158220 0.191284 0.165066 0.129761 0.122731 0.068939 0.229597
Kärnten 0.043173 1.000000 0.001130 0.131906 0.044612 0.098954 0.428166 -0.050934 0.102706
Niederösterreich 0.158220 0.001130 1.000000 0.342902 0.164417 0.309567 0.124061 0.189841 0.336890
Oberösterreich 0.191284 0.131906 0.342902 1.000000 0.235155 0.338845 0.176910 0.178404 0.270362
Salzburg 0.165066 0.044612 0.164417 0.235155 1.000000 0.152728 0.143906 0.152145 0.139911
Steiermark 0.129761 0.098954 0.309567 0.338845 0.152728 1.000000 0.162339 0.147560 0.090146
Tirol 0.122731 0.428166 0.124061 0.176910 0.143906 0.162339 1.000000 0.120427 0.161331
Vorarlberg 0.068939 -0.050934 0.189841 0.178404 0.152145 0.147560 0.120427 1.000000 0.014387
Wien 0.229597 0.102706 0.336890 0.270362 0.139911 0.090146 0.161331 0.014387 1.000000